import * as UserActions from '../actions/user-actions';

import { Action } from 'redux';
import { User } from '../models/user';

export interface UsersState {
    currentUser: User;
}

const initialState: UsersState = {
    currentUser: null
};

export const UsersReducer = function (state: UsersState = initialState, action: Action): UsersState {
    let currentUserState: UsersState;
    switch (action.type) {
        case UserActions.SET_CURRENT_USER:
            const user: User = (<UserActions.SetCurrentUserAction>).user;
            currentUserState = {
                currentUser: user
            };
            break;

        default:
            currentUserState = state;
            break;
    }
    return currentUserState;
};
